//
//  WelcomeViewController.m
//  weibo
//
//  Created by qiuming on 15/12/25.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "WelcomeViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <pop/POP.h>
@interface WelcomeViewController ()
@property (strong, nonatomic) UIImageView *backgroundView;
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *desLabel;
@end

@implementation WelcomeViewController

- (void)loadView {
    [super loadView];
    self.view = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ad_background"]];
    
    [self setupUI];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.iconView sd_setImageWithURL:[UserAccountViewModel sharedUserAccount].avatarUrl placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.iconView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-(self.view.center.y + 100));
    }];
    self.desLabel.alpha = 0;
    
    [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:5 options:0 animations:^{
        
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.desLabel.alpha = 1;
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter]postNotificationName:SwitchRootViewControllerNotification object:nil];
        }];
    }];
}

- (void)setupUI {
    // 添加控件
    [self.view addSubview:self.iconView];
    [self.view addSubview:self.desLabel];
    // 自动布局
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(-160);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_centerX);
        make.top.equalTo(self.iconView.mas_bottom).offset(12);
    }];
}

#pragma mark - 懒加载
- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc]init];
        _iconView.cornerRadius = 45;
    }
    return _iconView;
}

- (UILabel *)desLabel {
    if (_desLabel == nil) {
        _desLabel = [UILabel labelWithText:@"欢迎归来" textColor:[UIColor darkGrayColor] textFont:18];
    }
    return _desLabel;
}

@end
